package com.lhj.xxsc.order.controller;

import java.util.Arrays;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.lhj.xxsc.order.entity.OrderEntity;
import com.lhj.xxsc.order.service.OrderService;
import com.xxsc.common.utils.PageUtils;
import com.xxsc.common.utils.R;


/**
 * 订单
 *
 * @author leifengyang
 * @email leifengyang@gmail.com
 * @date 2019-10-08 09:56:16
 */
@RestController
@RequestMapping("order/order")
public class OrderController {
	@Autowired
	private OrderService orderService;

	/**
	 * 列表
	 */
	@RequestMapping("/list")
	//@RequiresPermissions("order:order:list")
	public R list(@RequestParam Map<String, Object> params) {
		PageUtils page = orderService.queryPage(params);

		return R.ok().put("page", page);
	}


	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	//@RequiresPermissions("order:order:info")
	public R info(@PathVariable("id") Long id) {
		OrderEntity order = orderService.getById(id);

		return R.ok().put("order", order);
	}

	/**
	 * 保存
	 */
	@RequestMapping("/save")
	//@RequiresPermissions("order:order:save")
	public R save(@RequestBody OrderEntity order) {
		orderService.save(order);

		return R.ok();
	}

	/**
	 * 修改
	 */
	@RequestMapping("/update")
	//@RequiresPermissions("order:order:update")
	public R update(@RequestBody OrderEntity order) {
		orderService.updateById(order);

		return R.ok();
	}

	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	//@RequiresPermissions("order:order:delete")
	public R delete(@RequestBody Long[] ids) {
		orderService.removeByIds(Arrays.asList(ids));
		return R.ok();
	}

	@GetMapping("/status/{orderSn}")
	public R getOrderStatus(@PathVariable("orderSn") String orderSn) {
		OrderEntity orderEntity = orderService.getOrderByOrderSn(orderSn);
		return R.ok().setData(orderEntity);
	}

	/**
	 * 查询登陆者的所有订单消息
	 *
	 * @param params
	 * @return
	 */
	@PostMapping("/listWithItem")
	public R listWithItem(@RequestBody Map<String, Object> params) {
		PageUtils page = orderService.queryPageWithItem(params);

		return R.ok().put("page", page);
	}
}
